/**
 * 
 */
package org.stars.daostars.operators;

import java.util.Date;

import org.stars.daostars.ConstraintOperator;
import org.stars.util.DateUtility;

/**
 * <b>Operatore</b>: <code>Equals</code>.
 * <p>
 * <b>Descrizione</b>:
 * Se <code>propertyValue</code> è guale
 * 
 * <p>
 * <b>Parametri utilizzati</b>:
 * <ul>
 * 		<li>property: SI</li>
 * 		<li>propertyValue: MUTUAMENTE ESCLUSIVO CON VALUE</li>
 * 		<li>value: MUTUAMENTE ESCLUSIVO CON PROPERTYVALUE</li>
 * </ul>
 * 
 * @author Francesco Benincasa (908099)
 *
 */
public class Equals implements ConstraintOperator {

	/**
	 * serial id
	 */
	private static final long serialVersionUID = 3818057546405094036L;

	/* (non-Javadoc)
	 * @see it.insiel.daostars.ConstraintOperator#execute(java.lang.Object, java.lang.Object, java.lang.String)
	 */
	@Override
	public boolean execute(Object property, Object propertyValue, String value) {
		boolean ret=false;
	
		if (propertyValue!=null)
		{
			ret= property.equals(propertyValue) ? true: false;
		} else if (value!=null)
		{
			if (property instanceof String)
			{				
				ret=property.equals(value) ? true :false;
			} else if (property instanceof Integer)
			{
				Integer app=Integer.parseInt(value);
				ret=property.equals(app) ? true :false;
			} else if (property instanceof Long)
			{
				Long app=Long.parseLong(value);
				ret=property.equals(app) ? true :false;
			} else if (property instanceof Double)
			{
				Double app=Double.parseDouble(value);
				ret=property.equals(app) ? true :false;
			} else if (property instanceof Date)
			{			
				String app=DateUtility.convertDateToString((Date) property);
				ret=property.equals(app) ? true :false;
			}  
		}
		
		return ret;
		
	}

}
